package com.xxg.renrenorder.dao.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;

/**
 * 地址信息
 *
 * @author xxg
 * @date 2020/11/16
 */
@Data
@ApiModel(value = "AddressInfo", description = "地址信息参数")
public class AddressInfo {
    @NotNull(message = "name不能为null")
    @ApiModelProperty(value = "收货人", required = true)
    private String name;
    @NotNull(message = "phone不能为null")
    @ApiModelProperty(value = "联系电话", required = true)
    private String phone;
    @NotNull(message = "address不能为null")
    @ApiModelProperty(value = "完整地址", required = true)
    private String address;
    @NotNull(message = "areaCode不能为null")
    @ApiModelProperty(value = "地区代码", required = true)
    private Integer areaCode;
    @ApiModelProperty(value = "市区代码")
    private Integer cityAreaCode;
    @ApiModelProperty(value = "省区代码")
    private Integer provinceAreaCode;

    public void setCityAndProvinceAreaCode() {
        if (areaCode != null) {
            int prefix = areaCode / 10000;
            // 直辖市
            boolean flag = prefix == 11 || prefix == 12 || prefix == 31 || prefix == 50;
            if (flag) {
                cityAreaCode = areaCode / 10000 * 10000;
            }else {
                cityAreaCode = areaCode / 100 * 100;
            }
            provinceAreaCode = areaCode / 10000 * 10000;
        }
    }

}
